package org.autoparser.exttree.termoper;

import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import org.autoparser.exttree.terms.ZExtractTerm;
import org.dom4j.Element;
import org.htmlparser.Node;

public class ZExtractTerms {
	private String key;
	private Vector<ZExtractTerm> extracts;
	private HashMap<String, Vector<String>> dataMap;
	private ZExtractTerms(){
		extracts = new Vector<ZExtractTerm>();
		dataMap = new HashMap<String, Vector<String>>();
	}
	public void extractTerms(Node node){
		if(extracts.size() > 0){
			for(ZExtractTerm t: extracts)
				t.extractTerm(node, dataMap);
		}
	}
	public static ZExtractTerms CreateExtractTerms(Element ele){
		if(ele.getName().compareToIgnoreCase("extraction") == 0){
			ZExtractTerms terms = new ZExtractTerms();
			terms.key = ele.attributeValue("key");
			if(terms.key == null)
				return null;
			List extEles = ele.elements();
			if(extEles != null && extEles.size() > 0){
				for(int j = 0; j < extEles.size(); ++j){
					ZExtractTerm tmp = ZTermFactory.CreateTerm((Element)(extEles.get(j)));
					if(tmp != null)
						terms.extracts.add(tmp);
				}
				return terms;
			}
		}
		return null;
	}
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public HashMap<String, Vector<String>> getDataMap() {
		return dataMap;
	}
	public void setDataMap(HashMap<String, Vector<String>> dataMap) {
		this.dataMap = dataMap;
	}
	
}
